<template>
	<view>
		<scroll-view scroll-y class="page">
			<!-- 头部 -->
			<cu-custom bgColor="bg-rgb" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">制令单转线</block>
			</cu-custom>
			<!-- 数据列表 -->
			<view class="line-item" v-for="item in lineList">
				<view class="line-name">产线名称：{{item.productlineName}}</view>
				<view class="but" @click="transferLine(item.productlineCode)">转线</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		name:"instructionWithTurn",
		data(){
			return {
				produceGrade:'',
				id:'',
				lineList:[],
				lineType:''
			}
		},
		onLoad(option) {
			this.produceGrade = this.$Route.query.produceGrade
			this.id = this.$Route.query.id
			this.lineType = this.$Route.query.lineType
			this.getListByType()
		},
		methods:{
			getListByType(){
				this.$http.get('chiefdata/mesChiefdataProductline/getListByType',{
					params:{
						type:this.produceGrade
					}
				}).then(res=>{
					if(res.data.success){
						let arr = []
						res.data.result.forEach(item=>{
							if(item.productlineCode != this.lineType){
								arr.push(item)
							}
						})
						this.lineList = arr
					}else{
						this.modal.show({ type:'error', content:res.data.message })
					}
				})
			},
			transferLine(productlineCode){
				uni.showModal({
					title: '制令单转线',
					content: '确认转线吗?',
					cancelText: '取消',
					confirmText: '确认',
					success: res => {
						if (res.confirm) {
							this.$http.get('produce/mesCommandbillInfo/transferLine',{
								params:{
									id:this.id,
									linetype:productlineCode,
								}
							}).then(res=>{
								if(res.data.success){
									this.modal.show({ type:'success', content:res.data.message })
									uni.$emit('transfer',{msg:'页面更新'})
									uni.navigateBack({
										delta:1
									})
								}else{
									this.modal.show({ type:'error', content:res.data.message })
								}
							})
						}
					}
				})
				
			}
		}
	}
</script>

<style lang="less">
	.line-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 10px 10px;
		
		.but {
			width: 200rpx;
			height: 64rpx;
			line-height: 50rpx;
			color: white;
			border-radius: 30rpx;
			padding: 10rpx 20rpx;
			text-align: center;
			background-color: #7D8CF0;
		}
	}
</style>
